package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.account.Account;

public class Client {
    private String name;
    private Gender gender;

    private Account account;

    public Client(String name, Gender gender, Account account) {
        if (name == null)
            throw new IllegalArgumentException("Name should be not null");
        if (gender == null)
            throw new IllegalArgumentException("Name should be not null");
        if (account == null)
            throw new IllegalArgumentException("Name should be not null");
        this.name = name;
        this.gender = gender;
        this.account = account;
    }

    public Account getAccount() {
        return account;
    }

    @Override
    public String toString() {
        StringBuffer result = new StringBuffer("Client ");
        result.append(gender.getPrefix()).append(" ")
                .append(name).append(" have ").append(account);

        return result.toString();
    }

    public String getName() {
        return name;
    }

    public Gender getGender() {
        return gender;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Client)) return false;

        Client client = (Client) o;

        if (!account.equals(client.account)) return false;
        if (gender != client.gender) return false;
        if (!name.equals(client.name)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + gender.hashCode();
        result = 31 * result + account.hashCode();
        return result;
    }
}
